package entity.result;

import enums.http.ResponseCodeEnum;

import java.io.Serializable;

/**
 * 数据返回基类
 */
public class BaseResult implements Serializable {

	private static final long serialVersionUID = 1L;
	private boolean success;
	private String code;
	private String mess;

	public BaseResult() {
	}

	public BaseResult(boolean success, ResponseCodeEnum responseCodeEnum) {
		this.success = success;
		this.code = responseCodeEnum.getCode();
		this.mess = responseCodeEnum.getMessage();
	}

	public BaseResult(boolean success, ResponseCodeEnum responseCodeEnum, String msg) {
		this.success = success;
		this.code = responseCodeEnum.getCode();
		this.mess = msg;
	}

	/*public static BaseResult success() {
		return new BaseResult(true, ResponseCodeEnum.SUCCESS);
	}

	public static BaseResult success(String msg) {
		return new BaseResult(true, ResponseCodeEnum.SUCCESS, msg);
	}

	public static BaseResult failed(ResponseCodeEnum responseCodeEnum, String msg) {
		return new BaseResult(false, responseCodeEnum, msg);
	}

	public static BaseResult failed(String msg) {
		return new BaseResult(false, ResponseCodeEnum.PARAM_ERROR, msg);
	}

	public static BaseResult failed(ResponseCodeEnum responseCodeEnum) {
		return new BaseResult(false, responseCodeEnum, responseCodeEnum.getMessage());
	}

	public static BaseResult failed() {
		return new BaseResult(false, ResponseCodeEnum.PARAM_ERROR, ResponseCodeEnum.PARAM_ERROR.getMessage());
	}

	public static BaseResult databaseError() {
		return new BaseResult(false, ResponseCodeEnum.DATABASE_OPERATION_ERROR);
	}

	public static BaseResult dataChanged() {
		return new BaseResult(false, ResponseCodeEnum.DATA_CHANGED);
	}
*/
	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMess() {
		return mess;
	}

	public void setMess(String mess) {
		this.mess = mess;
	}

	/**
	 * 响应成功
	 */
	public BaseResult responseSuccess() {
		this.setSuccess(true);
		this.setCode(ResponseCodeEnum.SUCCESS.getCode());
		this.setMess(ResponseCodeEnum.SUCCESS.getMessage());
		return this;
	}
	
	/**
	 * 响应成功
	 */
	public BaseResult responseSuccess(ResponseCodeEnum responseCodeEnum) {
		this.setSuccess(true);
		this.setCode(responseCodeEnum.getCode());
		this.setMess(responseCodeEnum.getMessage());
		return this;
	}
	
	/**
	 * 响应成功
	 */
	public BaseResult responseSuccess(ResponseCodeEnum responseCodeEnum,String message) {
		this.setSuccess(true);
		this.setCode(responseCodeEnum.getCode());
		this.setMess(message);
		return this;
	}

	/**
	 * 响应失败
	 */
	public BaseResult responseFail(ResponseCodeEnum responseCodeEnum, String message) {
		this.setSuccess(false);
		this.setCode(responseCodeEnum.getCode());
		this.setMess(message);
		return this;
	}

	/**
	 * 响应失败
	 */
	public BaseResult responseFail(ResponseCodeEnum responseCodeEnum) {
		this.setSuccess(false);
		this.setCode(responseCodeEnum.getCode());
		this.setMess(responseCodeEnum.getMessage());
		return this;
	}

}
